﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using System.IO;

namespace Diplomova_prace
{
    public partial class MainMenu : Form
    {
        private static string temp = "temp";
        private static string img = "img";
        private static string inValid = "Nevalidní";
        public static string PathTaskInt = "\\Cvicne_ulohy\\Numericka_integrace\\";
        public static string PathTaskDer = "\\Cvicne_ulohy\\Numericka_derivace\\";
        public static string PathTaskNel = "\\Cvicne_ulohy\\Nelinearni_rovnice\\";
        public static string PathTaskLin = "\\Cvicne_ulohy\\Linearni_rovnice\\";
        public static string tempProperty
        {
            get { return temp; }
        }
        public static string imgProperty
        {
            get { return img; }
        }
        public static string inValidProperty
        {
            get { return inValid; }
        }
        public static string PathTaskIntProperty
        {
            get { return PathTaskInt; }
        }
        public static string PathTaskDerProperty
        {
            get { return PathTaskDer; }
        }
        public static string PathTaskLinProperty
        {
            get { return PathTaskLin; }
        }
        public static string PathTaskNelProperty
        {
            get { return PathTaskNel; }
        }
        public static Dictionary<int, string> dictIntTagName = new Dictionary<int, string>();
        public static Dictionary<int, string> dictDerTagName = new Dictionary<int, string>();
        public static Dictionary<int, string> dictNelTagName = new Dictionary<int, string>();
        public static Dictionary<int, string> dictLinTagName = new Dictionary<int, string>();
        public MainMenu()
        {
            InitializeComponent();
            FillDictInt();
            FillDictDer();
            FillDictNel();
            FillDictLin(); 
        }

        private void RemoveHtmlInstance()
        {
            string directory = Directory.GetCurrentDirectory();
            List<string> files = Directory.GetFiles(directory).ToList();
            foreach (string file in files)
            {
                if ((file.Contains(temp) || file.Contains(img)) && Path.GetExtension(file) == ".html")
                {
                    File.Delete(Path.GetFullPath(file));
                }
            }
        }

        private void SelectIntegrationMethod_Click(object sender, EventArgs e)
        {
            int tag = int.Parse(((ToolStripMenuItem)sender).Tag.ToString());
            SelectIntegrationMethod(tag);
        }

        private void SelectDerivationMethod_Click(object sender, EventArgs e)
        {
            int tag = int.Parse(((ToolStripMenuItem)sender).Tag.ToString());
            SelectDerivationMethod(tag);
        }

        private void SelectNelinearSolutionMethod_Click(object sender, EventArgs e)
        {
            int tag = int.Parse(((ToolStripMenuItem)sender).Tag.ToString());
            SelectNelinearMethod(tag);

        }

        private void SelectLinearSolutionsMethod_Click(object sender, EventArgs e)
        {
            int tag = int.Parse(((ToolStripMenuItem)sender).Tag.ToString());
            SelectLinearMethod(tag);
        }

        private void MainMenu_FormClosing(object sender, FormClosingEventArgs e)
        {
            RemoveHtmlInstance();
        }

        private void konecToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RemoveHtmlInstance();
            this.Close();
        }

        private int SelectTask(string[] temp,string[] tasksWithPath)
        {
            SelectedTask st = new SelectedTask(temp.ToArray(), tasksWithPath);
            st.StartPosition = FormStartPosition.CenterParent;
            int indexTask = -1;
            if (DialogResult.OK == st.ShowDialog())
            {
                st.Close();
                indexTask = st.GetSelectedTask;
                return indexTask;
            }
            else
                return -1;
        }

        private int SelectMethod(Dictionary<int,string> dict)
        {
            SelectedMethod sm = new SelectedMethod(dict);
            sm.StartPosition = FormStartPosition.CenterParent;
            int methodTag = -1;
            string methodName = string.Empty;
            if (DialogResult.OK == sm.ShowDialog())
            {
                sm.Close();
                methodTag = sm.GetSelectedMethod;
                return methodTag;
            }
            else
                return -1;
        }

        private string[] OrderFiles(string PathDirectory)
        {
            DirectoryInfo di = new DirectoryInfo(PathDirectory);
            FileSystemInfo[] files = di.GetFileSystemInfos("*.xml");
            var orderedFiles = files.OrderBy(f => f.CreationTime);
            List<string> sortedFiles = new List<string>();
            foreach (FileSystemInfo item in orderedFiles)
                sortedFiles.Add(item.FullName);
            return sortedFiles.ToArray();
        }

        private void numerickáIntegraceToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            int methodTag = SelectMethod(dictIntTagName);
            if (methodTag < 0)
                return;
            string methodName = dictIntTagName[methodTag];

            string PathDirectory = string.Empty;
            if (!Directory.Exists(Directory.GetCurrentDirectory() + MainMenu.PathTaskIntProperty + methodName))
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + MainMenu.PathTaskIntProperty + methodName);
            PathDirectory = Directory.GetCurrentDirectory() + MainMenu.PathTaskIntProperty+ methodName;
            string[] tasksWithPath =  Directory.GetFiles(PathDirectory,"*.xml");
            tasksWithPath = OrderFiles(PathDirectory);

            Dictionary<string, string> dict;
            XMLParser xml = new XMLParser();
            string valid;
            string pathToXSD = Directory.GetFiles(PathDirectory, "*.xsd").First();
            List<string> temp = new List<string>();
            for (int i = 0; i < tasksWithPath.Length; i++)
            {
                xml = new XMLParser();
                valid = xml.CheckByXSD(pathToXSD, tasksWithPath[i]);
                dict = xml.ParserValOfEl(tasksWithPath[i]);
                if (valid == string.Empty)
                {
                    temp.Add("f(x)=" + dict["funkce"] + " od: " + dict["dolni_mez"] + " do: " + dict["horni_mez"]);
                }
                else
                {
                    temp.Add(MainMenu.inValidProperty + " xml : " +valid);
                }
            }

            int indexTask = SelectTask(temp.ToArray(), tasksWithPath);
            if (indexTask < 0)
                return;
            string funkce = string.Empty;
            string dolniMez = string.Empty;
            string horniMez = string.Empty;
            string pocetDilu = string.Empty;
            string presnost = string.Empty;
            string pocetBodu = string.Empty;
            xml = new XMLParser();
            dict = xml.ParserValOfEl(tasksWithPath[indexTask]);
            funkce = dict["funkce"];
            dolniMez = dict["dolni_mez"];
            horniMez = dict["horni_mez"];
            if (dict.ContainsKey("pocet_dilu"))
                pocetDilu = dict["pocet_dilu"];
            if (dict.ContainsKey("pocet_bodu"))
                pocetBodu = dict["pocet_bodu"];
            if (dict.ContainsKey("presnost"))
                presnost = dict["presnost"];

            SelectIntegrationMethod(methodTag, funkce, dolniMez, horniMez,pocetDilu,pocetBodu,presnost);
        }

        private void numerickáDerivaceToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            int methodTag = SelectMethod(dictDerTagName);
            if (methodTag < 0)
                return;
            string methodName = dictDerTagName[methodTag];

            string PathDirectory = string.Empty;
            if (!Directory.Exists(Directory.GetCurrentDirectory() + MainMenu.PathTaskDerProperty + methodName))
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + MainMenu.PathTaskDerProperty + methodName);
            PathDirectory = Directory.GetCurrentDirectory() + MainMenu.PathTaskDerProperty + methodName;
            string[] tasksWithPath = Directory.GetFiles(PathDirectory, "*.xml");
            tasksWithPath = OrderFiles(PathDirectory);

            Dictionary<string, string> dict;
            XMLParser xml = new XMLParser();
            string valid;
            string pathToXSD = Directory.GetFiles(PathDirectory, "*.xsd").First();
            List<string> temp = new List<string>();
            for (int i = 0; i < tasksWithPath.Length; i++)
            {
                xml = new XMLParser();
                valid = xml.CheckByXSD(pathToXSD, tasksWithPath[i]);
                dict = xml.ParserValOfEl(tasksWithPath[i]);
                if (valid == string.Empty)
                    temp.Add("f(x)=" + dict["funkce"] + " bod: " + dict["bod"]);
                else
                    temp.Add(MainMenu.inValidProperty + " xml : " + valid);

            }
            int indexTask = SelectTask(temp.ToArray(), tasksWithPath);
            if (indexTask < 0)
                return;
            string funkce = string.Empty;
            string bod = string.Empty;
            string krok = string.Empty;
            string presnost = string.Empty;

            xml = new XMLParser();
            dict = xml.ParserValOfEl(tasksWithPath[indexTask]);
            funkce = dict["funkce"];
            bod = dict["bod"];
            krok = dict["krok"];
            if (dict.ContainsKey("presnost"))
                presnost = dict["presnost"];

            SelectDerivationMethod(methodTag, funkce, bod, krok, presnost);
        }

        private void nelineárníRovniceToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            int methodTag = SelectMethod(dictNelTagName);
            if (methodTag < 0)
                return;
            string methodName = dictNelTagName[methodTag];

            string PathDirectory = string.Empty;
            if (!Directory.Exists(Directory.GetCurrentDirectory() + MainMenu.PathTaskNelProperty + methodName))
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + MainMenu.PathTaskNelProperty + methodName);
            PathDirectory = Directory.GetCurrentDirectory() + MainMenu.PathTaskNelProperty + methodName;
            string[] tasksWithPath = Directory.GetFiles(PathDirectory, "*.xml");
            tasksWithPath = OrderFiles(PathDirectory);

            Dictionary<string, string> dict;
            XMLParser xml = new XMLParser();
            string valid;
            string pathToXSD = Directory.GetFiles(PathDirectory, "*.xsd").First();
            List<string> temp = new List<string>();
            for (int i = 0; i < tasksWithPath.Length; i++)
            {
                xml = new XMLParser();
                valid = xml.CheckByXSD(pathToXSD, tasksWithPath[i]);
                dict = xml.ParserValOfEl(tasksWithPath[i]);
                if (valid == string.Empty)
                {
                    if (methodTag < 3)
                        temp.Add("úloha " + (i + 1) + " : f(x)=" + dict["funkce"] + " od: " + dict["dolni_mez"] + " do:" + dict["horni_mez"]);
                    else
                        temp.Add("úloha " + (i + 1) + " : f(x)=" + dict["funkce"] + " pocatecni hodnota: " + dict["pocatecni_hodnota"]);
                }
                else
                {
                    temp.Add(MainMenu.inValidProperty + " xml : " + valid);
                }

            }
            int indexTask = SelectTask(temp.ToArray(), tasksWithPath);
            if (indexTask < 0)
                return;
            string funkce = string.Empty;
            string dolniMez = string.Empty;
            string horniMez = string.Empty;
            string pocatecniHodnota = string.Empty;
            string pocetIteraci = string.Empty;
            string presnost = string.Empty;
            string derivace = string.Empty;
            string druhaDerivace = string.Empty;

            xml = new XMLParser();
            dict = xml.ParserValOfEl(tasksWithPath[indexTask]);
            funkce = dict["funkce"];
            pocetIteraci = dict["pocet_iteraci"];
            presnost = dict["presnost"];
            if (dict.ContainsKey("dolni_mez"))
                dolniMez = dict["dolni_mez"];
            if (dict.ContainsKey("horni_mez"))
                horniMez = dict["horni_mez"];
            if (dict.ContainsKey("pocatecni_hodnota"))
                pocatecniHodnota = dict["pocatecni_hodnota"];
            if (dict.ContainsKey("derivace"))
                derivace = dict["derivace"];
            if (dict.ContainsKey("druha_derivace"))
                druhaDerivace = dict["druha_derivace"];
            SelectNelinearMethod(methodTag, funkce, dolniMez, horniMez, pocatecniHodnota, pocetIteraci, presnost, derivace, druhaDerivace);
        }

        private void lineárníRovniceToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            int methodTag = SelectMethod(dictLinTagName);
            if (methodTag < 0)
                return;
            string methodName = dictLinTagName[methodTag];
            string PathDirectory = string.Empty;
            if (!Directory.Exists(Directory.GetCurrentDirectory() + MainMenu.PathTaskLinProperty + methodName))
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + MainMenu.PathTaskLinProperty + methodName);
            PathDirectory = Directory.GetCurrentDirectory() + MainMenu.PathTaskLinProperty + methodName;
            string[] tasksWithPath = Directory.GetFiles(PathDirectory, "*.xml");
            tasksWithPath = OrderFiles(PathDirectory);

            Dictionary<string, string> dict = null;
            XMLParser xml = new XMLParser();
            string valid;
            string pathToXSD = Directory.GetFiles(PathDirectory, "*.xsd").First();
            List<string> temp = new List<string>();
            List<string[,]> ListparseData;
            bool IsCorrectInput = false;
            List<string> ListStrings = null;
            for (int i = 0; i < tasksWithPath.Length; i++)
            {
                xml = new XMLParser();
                valid = xml.CheckByXSD(pathToXSD, tasksWithPath[i]);
                if (valid == string.Empty)
                {
                    dict = xml.ParserValOfEl(tasksWithPath[i]);
                    ListparseData = ParsingDataLinearTask(dict);
                    IsCorrectInput = CheckCorrectLinearXmls(ListparseData);
                    if (IsCorrectInput) 
                        ListStrings = LinearStrings(ListparseData);
                }
                else
                    temp.Add(MainMenu.inValidProperty + " xml : " + valid);
                if (IsCorrectInput)
                {
                    if (methodTag < 3)
                        temp.Add("Soustava: " + ListStrings[0] + " Vektor: " + ListStrings[1]);
                    else if (methodTag < 7)
                        temp.Add("Soustava: " + ListStrings[0] + Environment.NewLine + "Vektor: " + ListStrings[1] + Environment.NewLine + "Počáteční vektor: " + ListStrings[2] + Environment.NewLine + "Počet iterací:" + dict["pocet_iteraci"] + " přesnost:" + dict["presnost"]);
                    else
                        temp.Add("Soustava: " + ListStrings[0] + Environment.NewLine + "Vektor: " + ListStrings[1] + Environment.NewLine + "Počáteční vektor: " + ListStrings[2] + Environment.NewLine + "Počet iterací:" + dict["pocet_iteraci"] + " přesnost:" + dict["presnost"] + " faktor:" + dict["faktor"]);
                }
                else if (valid == string.Empty && !IsCorrectInput)
                    temp.Add(MainMenu.inValidProperty + " xml : " + "Nekorektní rozměry vstupních dat");

            }

            int indexTask = SelectTask(temp.ToArray(), tasksWithPath);
            if (indexTask < 0)
                return;
            string presnost = string.Empty;
            string faktor = string.Empty;
            string pocetIteraci = string.Empty;

            xml = new XMLParser();
            dict = xml.ParserValOfEl(tasksWithPath[indexTask]);
            ListparseData = ParsingDataLinearTask(dict);
            string[,] soustava = ListparseData[0];
            string[,] vektorB = ListparseData[1];
            string[,] pocApr = null;
            if (ListparseData.Count > 2)
                pocApr = ListparseData[2];
            if (dict.ContainsKey("presnost"))
                presnost = dict["presnost"];
            if (dict.ContainsKey("pocet_iteraci"))
                pocetIteraci = dict["pocet_iteraci"];
            if (dict.ContainsKey("faktor"))
                faktor = dict["faktor"];
            SelectLinearMethod(methodTag, soustava, vektorB, pocApr, faktor, pocetIteraci, presnost);
        }

        private List<string[,]> ParsingDataLinearTask(Dictionary<string, string> dict)
        {
            List<string> soustava = new List<string>();
            List<string> vektorB = new List<string>();
            List<string> pocApr = new List<string>();
            List<string> Rozmery = new List<string>();
            List<string[,]> ResultMatrices = new List<string[,]>();
            List<List<string>> Matrices = new List<List<string>>(); 
            string soustavaRozmer = null;
            string vektorBRozmer = null;
            string pocAprRozmer = null;

            foreach (string key in dict.Keys)
            {
                if (key.StartsWith("Soustava"))
                {
                    soustava.Add(dict[key]);
                    soustavaRozmer = key.Remove(0, key.IndexOf(':') + 1);
                }
                else if (key.StartsWith("VektorB"))
                {
                    vektorB.Add(dict[key]);
                    vektorBRozmer = key.Remove(0, key.IndexOf(':') + 1);
                }
                else if (key.StartsWith("PocatecniAproximace"))
                {
                    pocApr.Add(dict[key]);
                    pocAprRozmer = key.Remove(0, key.IndexOf(':') + 1);
                }
            }
            if (soustavaRozmer != null)
            {
                Rozmery.Add(soustavaRozmer);
                Matrices.Add(soustava);
            }
            if (vektorBRozmer != null)
            {
                Rozmery.Add(vektorBRozmer);
                Matrices.Add(vektorB);
            }
            if (pocAprRozmer != null)
            {
                Rozmery.Add(pocAprRozmer);
                Matrices.Add(pocApr);
            }
            for (int i = 0; i < Rozmery.Count; i++)
            {
                int RowCount = int.Parse(Rozmery[i].Substring(0, 1));
                int ColumnCount = int.Parse(Rozmery[i].Substring(2, 1));
                ResultMatrices.Add(new string[RowCount + 1, ColumnCount + 1]);
                int offset = RowCount + 1;
                for (int j = 0; j < RowCount + 1; j++)
                {
                    offset = (RowCount + 1) * j;
                    for (int k = 0; k < ColumnCount + 1; k++)
                        if (RowCount == ColumnCount)
                            ResultMatrices[i][j,k] = Matrices[i][k + offset];
                        else
                            ResultMatrices[i][j, k] = Matrices[i][j];
                }
            }
            return ResultMatrices;
        }

        private bool CheckCorrectLinearXmls(List<string[,]> input)
        {
            if (input[0].GetLength(0) != input[0].GetLength(1))
                return false;
            if (input[0].GetLength(0) != input[1].GetLength(0))
                return false;
            if (input.Count > 2)
                if (input[0].GetLength(0) != input[2].GetLength(0))
                    return false;
            return true;
        }

        private List<string> LinearStrings(List<string[,]> input)
        {
            List<string> res = new List<string>();
            StringBuilder sb;
            for (int i = 0; i < input.Count; i++)
            {
                sb = new StringBuilder();
                sb.Append("{");
                for (int j = 0; j < input[i].GetLength(0); j++)
                {
                    sb.Append("[");
                    for (int k = 0; k < input[i].GetLength(1); k++)
                    {
                        sb.Append(input[i][j, k]);
                        if (k + 1 != input[i].GetLength(1))
                            sb.Append(",");
                    }
                    sb.Append("]");
                    if (j + 1 != input[i].GetLength(0))
                        sb.Append(";");
                }
                sb.Append("}");
                res.Add(sb.ToString());
            }
            return res;
        }

        private IEnumerable<ToolStripMenuItem> GetItems(ToolStripMenuItem item)
        {
            foreach (ToolStripMenuItem dropDownItem in item.DropDownItems)
            {
                if (dropDownItem.HasDropDownItems)
                {
                    foreach (ToolStripMenuItem subItem in GetItems(dropDownItem))
                        yield return subItem;
                }
                yield return dropDownItem;
            }
        }

        private void SelectIntegrationMethod(int tag, string funkce="", string dolni_mez="", string horni_mez="", string pocet_dilu = "", string pocet_bodu = "", string presnost = "")
        {
            Integration_win integration;
            if (tag == 0)
                integration = new Integration_win(Integration_win.Methods.MidPoint,funkce,dolni_mez,horni_mez);
            else if (tag == 1)
                integration = new Integration_win(Integration_win.Methods.Trapezodial, funkce, dolni_mez, horni_mez);
            else if (tag == 2)
                integration = new Integration_win(Integration_win.Methods.Simpson, funkce, dolni_mez, horni_mez);
            else if (tag == 3)
                integration = new Integration_win(Integration_win.Methods.ThreeEighths, funkce, dolni_mez, horni_mez);
            else if (tag == 4)
                integration = new Integration_win(Integration_win.Methods.Bool, funkce, dolni_mez, horni_mez);
            else if (tag == 5)
                integration = new Integration_win(Integration_win.Methods.ComMidpoint, funkce, dolni_mez, horni_mez,pocet_dilu);
            else if (tag == 6)
                integration = new Integration_win(Integration_win.Methods.ComTrapezodial, funkce, dolni_mez, horni_mez, pocet_dilu);
            else if (tag == 7)
                integration = new Integration_win(Integration_win.Methods.ComSimpson, funkce, dolni_mez, horni_mez, pocet_dilu);
            else if (tag == 8)
                integration = new Integration_win(Integration_win.Methods.ComThreeEighths, funkce, dolni_mez, horni_mez, pocet_dilu);
            else if (tag == 9)
                integration = new Integration_win(Integration_win.Methods.ComBool, funkce, dolni_mez, horni_mez, pocet_dilu);
            else if (tag == 11)
                integration = new Integration_win(Integration_win.Methods.GaussLegendre, funkce, dolni_mez, horni_mez, pocet_dilu,pocet_bodu);
            else if (tag == 10)
                integration = new Integration_win(Integration_win.Methods.RombergIntegration, funkce, dolni_mez, horni_mez,string.Empty,string.Empty, presnost);
        }

        private void SelectDerivationMethod(int tag, string funkce = "", string bod = "", string krok = "", string presnost = "")
        {
            Derivation_win derivation;
            if (tag == 0)
                derivation = new Derivation_win(Derivation_win.Methods.FirstLinearDerivation, funkce, bod, krok);
            else if ( tag == 1)
                derivation = new Derivation_win(Derivation_win.Methods.FirstQuadraticDerivation, funkce, bod, krok);
            else if ( tag == 2)
                derivation = new Derivation_win(Derivation_win.Methods.SecondDerivation, funkce, bod, krok);
            else if (tag == 3)
                derivation = new Derivation_win(Derivation_win.Methods.RichardsonExtrapolation, funkce, bod, krok,presnost);
        }

        private void SelectNelinearMethod(int tag, string funkce = "", string dolni_mez = "", string horni_mez = "", string pocatecni_hodnota = "", string pocet_iteraci = "", string presnost = "", string derivace = "", string druhaDerivace = "")
        {
            Nelinear_solutions_win nelinear;
            if (tag == 0)
                nelinear = new Nelinear_solutions_win(Nelinear_solutions_win.Methods.BisectionMethod, funkce, dolni_mez, horni_mez, string.Empty, presnost, pocet_iteraci);
            else if (tag == 1)
                nelinear = new Nelinear_solutions_win(Nelinear_solutions_win.Methods.RegulaFalsiMethod, funkce, dolni_mez, horni_mez, string.Empty, presnost, pocet_iteraci);
            else if (tag == 2)
                nelinear = new Nelinear_solutions_win(Nelinear_solutions_win.Methods.SecantMethod, funkce, dolni_mez, horni_mez, string.Empty, presnost, pocet_iteraci);
            else if (tag == 3)
                nelinear = new Nelinear_solutions_win(Nelinear_solutions_win.Methods.NewtonsMethod, funkce, string.Empty, string.Empty, pocatecni_hodnota, presnost, pocet_iteraci, derivace,string.Empty);
            else if (tag == 4)
                nelinear = new Nelinear_solutions_win(Nelinear_solutions_win.Methods.SteffensensMethod, funkce, string.Empty, string.Empty, pocatecni_hodnota, presnost, pocet_iteraci,string.Empty);
            else if (tag == 5)
                nelinear = new Nelinear_solutions_win(Nelinear_solutions_win.Methods.HalleysMethod, funkce, string.Empty, string.Empty, pocatecni_hodnota, presnost, pocet_iteraci, derivace, druhaDerivace);
        }

        private void SelectLinearMethod(int tag, string[,] soustava = null, string[,] vektorB = null, string[,] PocatecniAproximace = null, string faktor = "", string pocetIteraci = "",string presnost= "")
        {
            Linear_solutions_win linear;
            if (tag == 0)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.GaussElimination,soustava,vektorB);
            else if (tag == 1)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.LUDecomposition,soustava,vektorB);
            else if (tag == 2)
                 linear = new Linear_solutions_win(Linear_solutions_win.Methods.CholeskyDecomposotion,soustava,vektorB);
            else if (tag == 3)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.JacobiMethodFolder,soustava,vektorB,PocatecniAproximace,null,pocetIteraci,presnost);
            else if (tag == 4)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.JacobiMethodMatrix, soustava, vektorB, PocatecniAproximace, null, pocetIteraci, presnost);
            else if (tag == 5)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.GaussSeidelMethodFolder, soustava, vektorB, PocatecniAproximace, null, pocetIteraci, presnost);
            else if (tag == 6)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.GaussSeidelMethodMatrix, soustava, vektorB, PocatecniAproximace, null, pocetIteraci, presnost);
            else if (tag == 7)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.SuperRelaxationMethodFolder, soustava, vektorB, PocatecniAproximace, faktor, pocetIteraci, presnost);
            else if (tag == 8)
                linear = new Linear_solutions_win(Linear_solutions_win.Methods.SuperRelaxationMethodMatrix, soustava, vektorB, PocatecniAproximace, faktor, pocetIteraci, presnost);
        }

        private void FillDictInt()
        {
            List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
            foreach (ToolStripMenuItem toolItem in menuStrip1.Items)
            {
                if (toolItem.Text == numerickáIntegraceToolStripMenuItem.Text)
                {
                    allItems.AddRange(GetItems(toolItem));
                }
            }
            List<string> nameMethods = new List<string>();
            List<int> Tags = new List<int>();
            for (int i = 0; i < allItems.Count; i++)
            {
                if (allItems[i].Tag != null)
                {
                    if (int.Parse((string)allItems[i].Tag) >= 5 && int.Parse((string)allItems[i].Tag) < 10)
                        nameMethods.Add("Složené " + allItems[i].Text);
                    else
                        nameMethods.Add(allItems[i].Text);
                    Tags.Add(int.Parse(allItems[i].Tag.ToString()));
                    dictIntTagName.Add(Tags.Last(), nameMethods.Last());
             
                }
           
            }
            dictIntTagName.Remove(10);
            dictIntTagName.Remove(11);
            dictIntTagName[10] = "Rombergova integrace";
            dictIntTagName[11] = "Gauss-Legendrova kvadratura";
        }

        private void FillDictDer()
        {
            List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
            foreach (ToolStripMenuItem toolItem in menuStrip1.Items)
            {
                if (toolItem.Text == numerickáDerivaceToolStripMenuItem.Text)
                {
                    allItems.AddRange(GetItems(toolItem));
                }
            }
            List<string> nameMethods = new List<string>();
            List<int> Tags = new List<int>();
            for (int i = 0; i < allItems.Count; i++)
            {
                if (allItems[i].Tag != null)
                {
                    nameMethods.Add(allItems[i].Text);
                    Tags.Add(int.Parse(allItems[i].Tag.ToString()));
                    dictDerTagName.Add(Tags.Last(), nameMethods.Last());
                }
            }
        }

        private void FillDictNel()
        {
            List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
            foreach (ToolStripMenuItem toolItem in menuStrip1.Items)
            {
                if (toolItem.Text == nelineárníRovniceToolStripMenuItem.Text)
                {
                    allItems.AddRange(GetItems(toolItem));
                }
            }
            List<string> nameMethods = new List<string>();
            List<int> Tags = new List<int>();
            for (int i = 0; i < allItems.Count; i++)
            {
                if (allItems[i].Tag != null)
                {
                    nameMethods.Add(allItems[i].Text);
                    Tags.Add(int.Parse(allItems[i].Tag.ToString()));
                    dictNelTagName.Add(Tags.Last(), nameMethods.Last());
                }
            }
        }

        private void FillDictLin()
        {
            List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
            foreach (ToolStripMenuItem toolItem in menuStrip1.Items)
            {
                if (toolItem.Text == lineárníRovniceToolStripMenuItem.Text)
                {
                    allItems.AddRange(GetItems(toolItem));
                }
            }
            List<string> nameMethods = new List<string>();
            List<int> Tags = new List<int>();
            for (int i = 0; i < allItems.Count; i++)
            {
                if (allItems[i].Tag != null)
                {
                    nameMethods.Add(allItems[i].Text);
                    Tags.Add(int.Parse(allItems[i].Tag.ToString()));
                    dictLinTagName.Add(Tags.Last(), nameMethods.Last());
                }
            }
        }





        

    }
}
